  var options = {
    data: function () {
      return {
        timeoutId: 0, // 计时器Id
        X: 0, // 轮播图偏移的位置
        // imgs: 轮播图数据
        imgs: ['./img/isc01.jpeg', './img/isc02.jpg', './img/isc03.jpg'],
        // qs: 用户填写的问卷数据
        qs: {
          username: null,
          hasFriend: null,
          howAge: null,
          whenWork: null,
          // hobby: null,
          hobby: [], // 这里必需写个空数组才行
          suggestion: null
        },
        isAgree: false,
        tmpWork: 1992, // 该数据只是为了用来控制工作radio的选中与否
        tmpAge: 18 // 该数据只是为了用来控制年龄radio的选中与否
      }
    },
    methods: {
      changeHandler: function () {
        // console.log('tmpAge')
        if (this.qs.howAge !== -1 && this.qs.howAge !== null) {
          this.tmpAge = this.qs.howAge
        }
        if (this.qs.whenWork !== -1 && this.qs.whenWork !== null) {
          this.tmpWork = this.qs.whenWork
        }
      },
      overHandler: function () {
        // 清空在timeoutId
        window.clearTimeout(this.timeoutId)
      },
      leaveHandler: function () {
        this.autoAnimate()
      },
      // 轮播动画
      animate: function (direction) {
        // -900 0, -900, -600, -300, 0
        var tmp = this.X + 300 * direction
        if (tmp < -600 || tmp > 0) {
          return (this.X = direction === 1 ? -600 : 0)
        }
        // this.X = this.X + 300 * direction
        this.X = tmp
      },
      // 上一张
      next: function () {
        this.animate(-1)
      },
      // 下一张
      prev: function () {
        this.animate(1)
      },
      // 自动轮播
      autoAnimate: function () {
        var _this = this
        _this.timeoutId = setTimeout(function () {
          _this.next()
          _this.autoAnimate()
        }, 2000)
      },
      sub () {
        if (!this.isAgree) {
          window.alert('请同意协议!')
          return
        }
        var options = {
          url: 'http://test.huoqishi.net/question',
          // url: 'http://127.0.0.1:8088/question',
          method: 'post',
          data: this.qs
        }
        axios(options).then(res => {
          if (res.data.code === 2000) {
            window.alert(res.data.errMsg)
            this.qs = {}
            this.isAgree = false
          }
        })
      }
    },
    mounted: function () {
      this.autoAnimate()
    }
  }
  var vm = new Vue(options)
  vm.$mount('#app')

//   /**
//  * Q1: username: string
//  * Q2: hasFriend: 0, 1, 2, 3
//  * Q3: howAge: 0, year(18, 19)
//  * Q4: whenWork: 0, year(1992)
//  * Q4: hobby: [0, 1, 2, 3, 4]
//  * Q5: suggestion
//  */
